package util;

import exception.TypeException;
import runtime.TypeFactory;



public class Type {
	private String typename = null; 
	private boolean _isArray = false;
	private int arraySize = -1;
	
	public String getName() {
		return typename;
	}

	public Type(String typename, boolean isArray, int size) {
		this.typename = typename;
		_isArray = isArray;
		arraySize = size;
	}
	
	public Type(String typename, boolean isArray) {
		this.typename = typename;
		if(isArray == true)
			throw new RuntimeException();
		_isArray = isArray;
		this.arraySize = -1;
	}
	
	public boolean isArray() {
		return _isArray;
	}

	public int getArraySize() {
		return arraySize;
	}
	
	public String toString(){
		return typename + (isArray() ? "[" + arraySize + ']' : "");
	}
	
	public boolean equals(Type other) {
		return this.toString().equals(other.toString());
	}

	public boolean isAClass() {
		TypeFactory tf = TypeFactory.getInstance();
		try {
			if( this.equals(tf.getType("int")) || this.equals(tf.getType("double")) || this.equals(tf.getType("char")) || this.equals(tf.getType("string")) || this.equals(tf.getType("bool")) ) {
				return false;
			}
		} catch (TypeException e) {
			// olac
		}
		return true;
	}
}
